import { httpClient } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { PageRequest, PageData } from '@/utils/common/types';
import { AjaxResult } from '../../../model';
import { TemplateMessageInputDto, TemplateMessageOutputDto } from './model';

/** 管理-模板消息URL枚举 */
enum Api {
  /** 读取模板消息 */
  Read = '/api/admin/templateMessage/read',
  /** 新增模板消息 */
  Create = '/api/admin/templateMessage/create',
  /** 更新模板消息 */
  Update = '/api/admin/templateMessage/update',
  /** 删除模板消息 */
  Delete = '/api/admin/templateMessage/delete',
  /** 发送模板消息 */
  Send = '/api/admin/templateMessage/send',
}

/**
 * 读取模板消息
 * @param request 分页请求
 * @param mode 错误消息模型
 */
export function readTemplateMessages(request: PageRequest, mode: ErrorMessageMode = 'message') {
  return httpClient.post<PageData<TemplateMessageOutputDto>>(
    {
      url: Api.Read,
      params: request,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 新增模板消息
 * @param dtos 消息DTO
 * @param mode 错误消息模型
 */
export function createTemplateMessages(
  dtos: TemplateMessageInputDto[],
  mode: ErrorMessageMode = 'message',
) {
  return httpClient.post<AjaxResult>(
    {
      url: Api.Create,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 更新模板消息
 * @param dtos 消息DTO
 * @param mode 错误消息模型
 */
export function updateTemplateMessages(
  dtos: TemplateMessageInputDto[],
  mode: ErrorMessageMode = 'message',
) {
  return httpClient.post<AjaxResult>(
    {
      url: Api.Update,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 删除模板消息
 * @param ids 消息编号
 * @param mode 错误消息模型
 */
export function deleteTemplateMessages(
  ids: (string | bigint)[],
  mode: ErrorMessageMode = 'message',
) {
  return httpClient.post<AjaxResult>(
    {
      url: Api.Delete,
      params: ids,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 发送模板消息
 * @param ids 消息编号
 * @param mode 错误消息模型
 */
export function sendTemplateMessages(ids: (string | bigint)[], mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: Api.Send,
      params: ids,
    },
    {
      errorMessageMode: mode,
    },
  );
}
